package com.example.mygesture;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnTouchListener ,View.OnClickListener{
    TextView tv;
    float startx;
    float starty;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        InitiView();


    }

    private void InitiView() {
        tv = findViewById(R.id.tv);
        tv.setOnTouchListener(this);
//        tv.setOnClickListener(this);

    }

    public boolean onTouch(View v, MotionEvent event) {

        // TODO Auto-generated method stub
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startx = event.getX();
                starty = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                float nowx = event.getX();
                float nowy = event.getY();
                float disX = nowx - startx;// x方向移动的距离
                float disY = nowy - starty;// y方向移动的距离
                // 当x方向移动的距离大于y方向移动的距离时
                if (Math.abs(disX) > Math.abs(disY) && disX > 0) {
                    tv.setText("往右滑");
                } else if (Math.abs(disX) > Math.abs(disY) && disX < 0) {
                    tv.setText("往左滑");
                } else if (Math.abs(disX) < Math.abs(disY) && disY > 0) {
                    tv.setText("往下滑");
                } else {
                    tv.setText("往上滑");
                }


                startx = (int) event.getRawX();
                starty = (int) event.getRawY();
                break;
            case MotionEvent.ACTION_UP:
        }
        return true;
    }


    @Override
    public void onClick(View view) {
        startActivity(new Intent(MainActivity.this, GA.class));

    }
}
